import { defineStore } from 'pinia'
import { ref } from 'vue'


//定义store
//defineStore(仓库的唯一标识, ()=>{ ... })
//存储当前用户信息的pinia仓库
export const UserStore = defineStore('userStore', () => {

    const userInfo = ref({
      id: null,
      name: null,
      password: null,
      phone: null,
      email: null,
      status: null,
      avatar: null,
      isAuthor: null,
      lastLoginTime: null,
      createTime: null,
      updateTime: null,
    })
    const setUserInfo = (data) => {
      userInfo.value = data
    }
    const cleanUserInfo = async() => {
      Object.keys(userInfo.value).forEach(key => {
        userInfo.value[key] = null;
      });
    }
    


  //向外暴露的变量或方法
  return {
    userInfo,
    setUserInfo,cleanUserInfo
  }
// },{
//   // 持久化配置
//   persist: {
//     key: 'wanXiang_userInfo',
//     pick: ['userInfo'], // 指定需要持久化的字段（不写pick默认全部持久化）
//     storage: sessionStorage, // 指定存储位置
//   }
})



